package com.voxel.sense.infomsg.module.publish.details;

import android.text.TextUtils;

import com.example.com.common.app.BasePresenter;
import com.example.com.common.factory.data.DataSource;

import java.util.List;

import cyy.example.com.facotry.constants.CommonConstants;
import cyy.example.com.facotry.model.api.BaseEntity;
import cyy.example.com.facotry.model.api.response.PublishFilesEntity;
import cyy.example.com.facotry.net.helper.FirmNetHelper;

/**
 * Created by ChenYiYao on 2018/10/23.
 * des :
 */
public class PublishDetPresenter extends BasePresenter<PublishDetContract.View> implements PublishDetContract.Presenter, DataSource.Callback<BaseEntity<PublishFilesEntity>> {

    public PublishDetPresenter(PublishDetContract.View view) {
        super(view);
    }


    @Override
    public void doLoad(String recID) {
        if (TextUtils.isEmpty(recID)) {
            mView.showError("查询错误");
        } else {
            mView.showLoading("");
            FirmNetHelper.getPublishFile(recID, this);
        }


    }

    @Override
    public void onDataLoaded(BaseEntity<PublishFilesEntity> data, int reqId) {
        if (mView == null)
            return;

        mView.dimissLoading();
        if (data.isSuccess() && data.getData() != null) {
            List<String> recFilePath = data.getData().getRecFilePath();
            for (int i = 0; i < recFilePath.size(); i++) {
                String s = recFilePath.get(i);
                recFilePath.set(i, CommonConstants.FILE_FIRM_URL + s);
            }
            mView.onLoadDetails(data.getData().getFileStr(), data.getData().getRecFilePath());
        } else {
            mView.showError("获取发布文件失败");
        }
    }

    @Override
    public void onDataNotAvailable(String strRes, int reqId) {
        if (mView != null) {
            mView.dimissLoading();
            mView.showError("获取发布文件失败");
        }
    }
}
